home *** CD-ROM | disk | FTP | other *** search
- #ifndef lint
- static char SccsId[]= "@(#)ob_box.c V1.17 3/13/95";
- #endif
- /*
- | file name - ob_box.c
- |===========================================================================
- |
- | This program is an example of how the function VOobBox() works.
- | It loads in a view (ob_box.v) that contains different objects.
- | It waits for the user to select and object. It then prints out
- | the coordinates of the "boxes" returned from VOobBox().
- | It also uses these boxes to draw a rectangle object behind the object.
- |
- | The program can be exited by typing the letter 'q' or the right
- | mouse button.
- |===========================================================================
- */
- #include <windows.h>
- /*
- * DV-Tools header files
- */
- #include "std.h" /* <stdio.h> etc., scalar & macro definitions */
- #include "dvstd.h" /* public types & constants */
- #include "dvtools.h" /* constants used by T routines */
- #include "dvGR.h" /* constants used by window mgt & GR routines */
- #include "VOstd.h" /* constants used by VO & VOob routines */
- #include "Tfundecl.h" /* T routines (screens, drawports & views) */
- #include "VOfundecl.h" /* VO routines (objects) */
- #include "VUerfundecl.h" /* VUer routines (event handling routines) */
-
- /* Constants */
- #define DVPATH (char *)NULL
- #define DISPFORMS_STB (char *)NULL
- #define DVDEVICE (char *)NULL
- #define DVCOLORTABLE (char *)NULL
- #define VIEW_NAME "ob_box.v"
- #define SCREEN_VIEWPORT (RECTANGLE *)NULL
- #define DRAWING_VIEWPORT (RECTANGLE *)NULL
-
- typedef struct
- {
- OBJECT rectobj;
- OBJECT ll_ptobj;
- OBJECT ur_ptobj;
- OBJECT msg_obj;
- } BOX_INFO;
-
- /* Functions defined in ob_box.c */
- void DisplayBoundingBox V_P_((OBJECT location, DRAWPORT drawport,
- BOX_INFO *box));
- /* display bounding box of selected object */
-
- /*
- * MAIN PROGRAM
- */
- int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
- LPSTR lpCmdLine, int nCmdShow )
- {
- INT argc = 0;
- CHAR **argv;
-
- /*
- * program arguments
- * argv[1] - display device name (default is to use DVDEVICE)
- */
-
- /* Define & initialize device name and view filename */
- char *device_name = DVDEVICE; /* default device name */
- char *view_name = VIEW_NAME; /* default view name */
-
- /* Define display variables */
- OBJECT screen; /* display device, the window */
- DRAWPORT drawport; /* how & where to display picture, picture frame */
- VIEW view; /* picture representation of the view file */
-
- /* Control loop variables */
- OBJECT location; /* the event representation */
-
- /* Other variables */
- OBJECT drawing; /* graphical representation of screen */
- BOX_INFO box; /* bounding box structure */
- ATTRIBUTES atts; /* attribute structure */
- int Quit = NO; /* flag to quit program */
-
-
- /*--------------------
- * Initialization
- *
- * TInit: perform the initialization of DV-Tools
- * TInit reads your configuration file and any
- * environment variables or logical names set.
- */
- make_argv(&argc,&argv,GetCommandLine());
- TInit( DVPATH, DISPFORMS_STB );
-
- /*
- * TscOpenSet: open a device as a screen object using
- * specified attributes
- * TscErase: erase the entire screen in the default
- * background color
- *
- * Set exposure block to YES to insure the window
- * is ready for drawing when TdpDraw is called.
- */
- if (argc > 1)
- device_name = argv[1];
- screen = TscOpenSet (device_name, DVCOLORTABLE,
- V_X_EXPOSURE_BLOCK, YES,
- V_ACTIVE_CURSOR, V_END_OF_LIST);
- if (!screen)
- {
- printf ("Must specify device on command line or");
- printf (" in DataViews configuration file.\n");
- S_EXIT (EXIT_ERR);
- }
- TscErase (screen);
-
- /*
- * VOscWinEventMask: sets the screen's window event mask
- */
- VOscWinEventMask ((ULONG) V_KEYPRESS | V_BUTTONPRESS | V_EXPOSE | V_RESIZE,
- (ULONG) 0);
-
- /*
- * TviLoad: Load a view in from a file, the view
- * name is ob_box.v.
- */
- view = TviLoad (view_name);
- if (!view)
- {
- printf ("Could not load view from file ");
- printf ("%s.\n", view_name);
- S_EXIT (EXIT_ERR);
- }
-
- /*
- * TdpCreate: Create a DV-Tools window, a drawport.
- * The drawport is attached to the screen object
- * specified while view specifies the view to be
- * displayed on the screen.
- */
- drawport = TdpCreate (screen, view, SCREEN_VIEWPORT, DRAWING_VIEWPORT);
-
- /*
- * TviGetDrawing: Gets a view's drawing object
- * TdrGetNamedObject: Gets a named object from a drawing.
- *
- * Get the message string object from the drawing.
- */
- drawing = TviGetDrawing (view);
- box.msg_obj = TdrGetNamedObject (drawing, "msg_obj");
-
- /*
- * VOuAtInit: Sets all attribute fields to EMPTY_FIELD
- * VOcoCreate: Create a color object
- * VOptCreate: Create a point object
- * VOreCreate: Create a rectangle
- *
- * Create a generic rectangle object which will be moved and
- * drawn behind each selected object to represent the objects
- * bounding box.
- */
- VOuAtInit (&atts);
- atts.fill_status = FILLED_OBJECT;
- atts.foreground_color = VOcoCreate (COLOR_NAME, "red");
- box.ll_ptobj = VOptCreate (WORLD_COORDINATES, 0, 0, (OBJECT) NULL);
- box.ur_ptobj = VOptCreate (WORLD_COORDINATES, 0, 0, (OBJECT) NULL);
- box.rectobj = VOreCreate (box.ll_ptobj, box.ur_ptobj, &atts);
-
- /*
- * TdpDraw: Draw the contents of the drawport
- */
- TdpDraw (drawport);
-
- /*
- * This loops waiting for the user to pick an object or the 'q' key.
- * If they pick an object, the bounding box for the object is calculated.
- * The world coordinates and the pixel offset_vp is printed.
- * The bounding box is drawn behind the object.
- */
- FOREVER
- {
- /*
- * VOloWinEventPoll: Poll for the next window event.
- * The polling mode used is V_WAIT.
- * Therefore, VOloWinEventPoll does not
- * return until a masked event is
- * generated. V_WAIT always produces
- * a valid location object.
- */
- location = VOloWinEventPoll (V_WAIT);
-
- /*
- * VOloType: returns the type of event. These types
- * match event types specified in VOscWinEventMask.
- */
- switch (VOloType (location))
- {
-
- case V_RESIZE:
- /*
- * The window size has been changed.
- * TscReset: Resets all screen drawports after
- * window resizing
- */
- TscReset (screen);
- break;
-
- case V_EXPOSE:
- /*
- * VOloRegion: Returns a rectangle representing the
- * exposed region on the screen.
- * TscRedraw: After erasing, redraws all the drawports
- * in the screen.
- * A portion of the window has been exposed and needs
- * to be redrawn.
- */
- TscRedraw (screen, VOloRegion (location));
- break;
-
- case V_KEYPRESS:
- /*
- * Check key selected.
- * VOloKeySym: Returns the key symbol value of the
- * location object
- *
- * If the key symbol represents the characters 'q'
- * or 'Q' then quit the program.
- */
- switch (VOloKeySym (location))
- {
- case 'q':
- case 'Q':
- Quit = YES;
- break;
-
- default:
- break;
- }
-
- case V_BUTTONPRESS:
- /*
- * VOloButton: Returns the button that was pressed
- *
- * The right mouse button exits the program.
- */
- if (VOloButton (location) == 3)
- Quit = YES;
- else
- DisplayBoundingBox (location, drawport, &box);
- break;
-
- default:
- break;
- }
-
- /* exit the program */
- if (Quit == YES)
- break;
-
- }
-
- /*--------------------
- * Termination
- *
- * TdpDestroy: Destroy the drawport,
- * TviDestroy: Destroy the view, freeing the allocated memory
- * TscCloseCurrentScreen: Close the current display screen
- * TTerminate: Perform the clean-up for DV-Tools
- */
- TdpDestroy (drawport);
- TviDestroy (view);
- TscCloseCurrentScreen ();
- TTerminate ();
- return EXIT_OK;
- }
-
- void
- DisplayBoundingBox (location, drawport, box)
- OBJECT location;
- DRAWPORT drawport;
- BOX_INFO *box;
- {
- OBJECT sel_object;
- RECTANGLE wvp, offset_vp;
- char msg_str[255];
-
- /*
- * TloGetSelectedObject: Gets the selected object.
- *
- * Display a bounding box for the selected object. If
- * no object was selected then return.
- */
- sel_object = TloGetSelectedObject (location);
- if (sel_object)
- {
- /*
- * VOobBox: Get an object's bounding box
- *
- * Obtain the bounding box for the selected object in world
- * coordinates.
- */
- VOobBox (sel_object, &wvp, &offset_vp);
-
- /*
- * Create a message string containing the world coordinate
- * information of the bounding box. The string will be
- * displayed by the message text object.
- */
- sprintf (msg_str,
- "world coordinate box = {%ld,%ld,%ld,%ld}\npixel offset_vp = {%ld,%ld,%ld,%ld}",
- wvp.ll.x, wvp.ll.y, wvp.ur.x, wvp.ur.y,
- offset_vp.ll.x, offset_vp.ll.y,
- offset_vp.ur.x, offset_vp.ur.y);
-
- /*
- * TdpEraseObject: Erases an object from a drawport
- * VOtxSetString: Set the string for the text object
- * TdpDrawObject: Draw an object to a drawport
- */
- TdpEraseObject (drawport, box->msg_obj);
- VOtxSetString (box->msg_obj, msg_str);
- TdpDrawObject (drawport, box->msg_obj);
-
- /*
- * TdpWorldToScreen: Converts world to screen coordinates
- */
- TdpWorldToScreen (drawport, &wvp.ll, &wvp.ll);
- TdpWorldToScreen (drawport, &wvp.ur, &wvp.ur);
-
- /*
- * Add the offset which is in screen coordinates to the
- * converted coordinates (screen).
- */
- wvp.ll.x += offset_vp.ll.x;
- wvp.ll.y += offset_vp.ll.y;
- wvp.ur.x += offset_vp.ur.x;
- wvp.ur.y += offset_vp.ur.y;
-
- /*
- * TdpScreenToWorld: Converts screen to world coordinates
- */
- TdpScreenToWorld (drawport, &wvp.ll, &wvp.ll);
- TdpScreenToWorld (drawport, &wvp.ur, &wvp.ur);
-
- /*
- * VOptMove: Moves a point object
- *
- * Move the point objects for the bounding box to a new
- * position. The bounding box is moved to an absolute position.
- */
- VOptMove (box->ll_ptobj, DV_ABSOLUTE, (int) wvp.ll.x, (int) wvp.ll.y);
- VOptMove (box->ur_ptobj, DV_ABSOLUTE, (int) wvp.ur.x, (int) wvp.ur.y);
-
- /*
- * TdpDrawObject: draw an object to a drawport
- *
- * Draw the bounding box rectangle object and redraw the
- * selected object.
- */
- TdpDrawObject (drawport, box->rectobj);
- TdpDrawObject (drawport, sel_object);
- }
- }
-